//
//  HomeNewsDetailCell.m
//  yunyan
//
//  Created by haichuang on 2018/3/27.
//  Copyright © 2018年 haichuang. All rights reserved.
//

#import "HomeNewsDetailCell.h"


@implementation HomeNewsDetailCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self createTopCell];
        
    }
    return self;
}

-(void)createTopCell{
    
    WeakSelf;
    _titleLable = [[UILabel alloc] init];
    [self addSubview:_titleLable];
    [_titleLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo (weakSelf.mas_left).offset (12.0f);
        make.top.equalTo (weakSelf.mas_top).offset (20.0f);
        make.right.equalTo (weakSelf.mas_right).offset (-12.0f);
    }];
    _titleLable.text = @"贵州省委省政府举行2018年春节团拜会";
    _titleLable.font = [UIFont boldSystemFontOfSize:18];
    _titleLable.textColor = RGBA(51, 51, 51, 1);
    _titleLable.numberOfLines = 0;
    
    //这个之后需要修改 不然页面显示不完
    _fromLable = [[UILabel alloc] init];
    [self addSubview:_fromLable];
    [_fromLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo (weakSelf.mas_left).offset (12.0f);
        make.top.equalTo (_titleLable.mas_bottom).offset (16.0f);
        make.right.equalTo (weakSelf.mas_right).offset (-12.0f);
    }];
    _fromLable.text = @"来源: 贵州日报 作者: 张明 256浏览 2018-02-14 10:00:00";
    _fromLable.font = [UIFont boldSystemFontOfSize:10];
    _fromLable.textColor = RGBA(102, 102, 102, 1);
    _fromLable.numberOfLines = 0;
    UIView * lineView = [[UIView alloc] init];
    [self addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo (weakSelf);
        make.height.equalTo (@(0.5f));
        make.top.equalTo (_fromLable.mas_bottom).offset (2.0);
        
        
    }];
    lineView.backgroundColor = RGBA(241, 241, 241, 1);
   
    
    UIView * imageBGview = [[UIView alloc] init];
    [self addSubview:imageBGview];
    
    [imageBGview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo (_fromLable.mas_bottom).offset (25.f);
        make.left.right.equalTo (_titleLable);
        
    }];
    
    
    //此处可以传view数组
    NSMutableArray * viewARR = [NSMutableArray array];
    for (int a = 0; a < 2; a ++) {
        _image = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
        
        [viewARR addObject:_image];
        
    }
    

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        // NSLog(@"******%@",contenview);
    });
    
    UIView * lastView ;
   
    for (int i = 0; i < viewARR.count ; i++) {
        UIImageView * view = viewARR[i];
        [imageBGview addSubview:view];
        
        [view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo (imageBGview.mas_left);
            make.right.equalTo (imageBGview.mas_right);
            make.top.equalTo(lastView ? lastView.mas_bottom: @0).offset(10);
            make.height.equalTo (view.mas_width).multipliedBy (0.5);
        }];
        view.image = [UIImage imageNamed:@"home_list_new"];
        lastView = view;
        
        //        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        //            NSLog(@"=======%d___%@",i,lastView);
        //        });
    }
    
    [imageBGview mas_updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(lastView.mas_bottom);
    }];
    
    
    //内容详情
    _detailLabel = [[UILabel alloc]init];
    [self addSubview:_detailLabel];
    [_detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo (imageBGview.mas_bottom).offset (20.f);
        make.left.right.equalTo (_titleLable);
        
    }];
    
    _detailLabel.numberOfLines = 0;
    _detailLabel.textColor = RGBA(102, 102, 102, 1);
    _detailLabel.text = @" 2月13日,省委、省政府在贵州饭店国际会议中心举行2018年春节团拜会。省领导同我省各族各界人士代表欢聚一堂,共贺新春佳节。\n\n2月13日,省委、省政府在贵州饭店国际会议中心举行2018年春节团拜会。省领导同我省各族各界人士代表欢聚一堂,共贺新春佳节。\n\n孙志刚在致辞中代表省委、省人大常委会、省政府、省政协,向全省各族人民,向所有关心支持贵州改革发展的各界朋友拜年,祝福大家新年好。他说,刚刚过去的2017年收获满满,让人难忘、令人振奋。党的十九大胜利召开,为我们描绘了美好的前景。习近平总书记参加贵州省代表团讨论并发表重要讲话,给予我们信念的感召、进取的力量、胜利的信心。全省各族干部群众以苦干实干、奋力赶超的斗志和豪情,推动经济发展、脱贫攻坚、改革开放、民生保障、精神面貌、政治生态持续向好,由衷地向全省各级干部、各族群众、各界人士点赞、致敬。";
    _detailLabel.font = [UIFont  systemFontOfSize:15];
    _detailLabel.numberOfLines = 0;
    
    UIView * btnView = [[UIView alloc]init];
    [self addSubview:btnView];
    [btnView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo (weakSelf.mas_centerX);
        make.width.equalTo (@(180));
        make.top.equalTo (_detailLabel.mas_bottom).offset(20.0f);
        make.bottom.equalTo (weakSelf.mas_bottom).offset (-20.0f);
        make.height.equalTo (@(30.f));
    }];
    btnView.layer.masksToBounds = YES;
    btnView.layer.cornerRadius = 5;
    
 
    //点赞
    _likeBtn = [[UIButton alloc] init];
    [btnView addSubview:_likeBtn];
    [_likeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.bottom.equalTo (btnView);
    }];
    
    
    _likeBtn.backgroundColor = RGBA(243, 245, 248, 1);
    [_likeBtn setTitleColor:RGBA(102, 102, 102, 1) forState:UIControlStateNormal];
    _likeBtn.titleLabel.font = [UIFont systemFontOfSize:12.0f];
    [_likeBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, 12, 0, 0)];
    [_likeBtn setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
    [_likeBtn setTitle:@"点赞" forState:UIControlStateNormal];
    [_likeBtn setImage:[UIImage imageNamed:@"new_praise_default"] forState:UIControlStateNormal];
    [_likeBtn addTarget:self action:@selector(likeBtnClicked) forControlEvents:UIControlEventTouchUpInside];
    //收藏
    _collectionBtn = [[UIButton alloc] init];
    [btnView addSubview:_collectionBtn];
    [_collectionBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.top.bottom.equalTo (btnView);
        make.width.equalTo(_likeBtn.mas_width);
        make.left.equalTo (_likeBtn.mas_right);
    }];
    
    _collectionBtn.backgroundColor = RGBA(243, 245, 248, 1);
    [_collectionBtn setTitleColor:RGBA(102, 102, 102, 1) forState:UIControlStateNormal];
    _collectionBtn.titleLabel.font = [UIFont systemFontOfSize:12.0f];
    [_collectionBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, 12, 0, 0)];
    [_collectionBtn setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
    [_collectionBtn setTitle:@"收藏" forState:UIControlStateNormal];
    [_collectionBtn setImage:[UIImage imageNamed:@"new_collection_default"] forState:UIControlStateNormal];
    [_collectionBtn addTarget:self action:@selector(collectionBtnClicked) forControlEvents:UIControlEventTouchUpInside];
    
   
    
}

-(void)likeBtnClicked{
    if (_isSelected) {
        [_likeBtn setImage:[UIImage imageNamed:@"new_praise_default"] forState:UIControlStateNormal];
        _isSelected = NO;
    }else{
        [_likeBtn setImage:[UIImage imageNamed:@"new_praise_pressed"] forState:UIControlStateNormal];
        _isSelected = YES;
    }
}
-(void)collectionBtnClicked{
    
    if (_isCollection) {
        [_collectionBtn setImage:[UIImage imageNamed:@"new_collection_default"] forState:UIControlStateNormal];
        _isCollection = NO;
    }else{
        [_collectionBtn setImage:[UIImage imageNamed:@"new_collection_pressed"] forState:UIControlStateNormal];
        _isCollection = YES;
    }
}



@end
